package cn.com.dhc.danlu.widget.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.util.TipCountUtil;
import cn.com.dhc.danlu.widget.BadgeView;
import cn.com.hd.mall.web.webservices.entity.response.common.GetTopicListResponse.TopicListModel;

/**
 * @author wuhaiyang
 */
public class SelectTypeGridAdapter extends MyBaseAdapter {
    private BadgeView mMyOrderBadgeView;

    public SelectTypeGridAdapter(Context context) {
        super(context);
    }

    public void refreshBadge(boolean isOrderBadge, int count) {
        if (null != mMyOrderBadgeView) {
            if (count > 0) {
                mMyOrderBadgeView.show();
                mMyOrderBadgeView.setText(TipCountUtil.cover(count, TipCountUtil.SMALL_FLAG));
            } else {
                mMyOrderBadgeView.hide();
            }
        }
    }

    @Override
    protected View createView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.dl_item_selectype, parent, false);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        TopicListModel model = (TopicListModel) getItem(position);
        mHolder.tvDescription.setText(model.getTopicTitle());
        mHolder.ivPic.setImageURI(Uri.parse(model.getPicUrl()));
        // 后期更换判断标准
        String type = model.getTopicType();
        if (type.equals("T11")) {
            if (null == mMyOrderBadgeView) {
                mMyOrderBadgeView = new BadgeView(mInflater.getContext(), mHolder.ivPic);
                mMyOrderBadgeView.setTextSize(9);
                mMyOrderBadgeView.hide();
            }
        }
        return convertView;
    }

    public static class ViewHolder {
        SimpleDraweeView ivPic;
        TextView tvDescription;

        public ViewHolder(View view) {
            ivPic = (SimpleDraweeView) view.findViewById(R.id.civ_type);
            tvDescription = (TextView) view.findViewById(R.id.tv_type_des);
        }
    }
}